<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0028)http://jdbi.org/archive.html -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>


<title>abacus-common</title>

<script type="text/javascript" src="./css/ga.js"></script>
<script type="text/javascript">
	if (top.location != self.location)
		top.location.replace(self.location);
</script>

<link href="./css/css" rel="stylesheet" type="text/css"></link>
<link href="./css/css(1)" rel="stylesheet" type="text/css"></link>
<link rel="stylesheet" href="./css/syntax.css" type="text/css"></link>
<link rel="stylesheet" href="./css/screen.css" type="text/css"></link>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-65247258-1', 'auto');
  ga('send', 'pageview');
</script>

</head>
<body>
	<div id="site">
		<h1>
			<a href="./index.html">abacus-common</a> <span id="navigation"> <a href="./docs.html">Docs</a> | <a href="./download.html">Download</a>
				| <a href="./api-docs/index.html">Javadoc</a> | <a href="./faq.html">FAQ</a> | <a href="./community.html">Community</a>
			</span>
		</h1>
	</div>

	<div id="content">

		<div id="page">

			<h1>Naming Convention</h1>
			<p>As we may know, by the naming convention, we can reduce a lot of efforts/headaches in different kinds of configuration/mapping by annotation/xml or even in codes. 
			Naming convention makes our codes consistent, integrated and much cleaner.</p>
				
				<p>Here are the three naming policies mostly used by people to name database tables/columns: </p>
				
				<li><b>Lower case with underscore:</b></li>
				<!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008000; font-weight: bold">CREATE</span> <span style="color: #008000; font-weight: bold">TABLE</span> account(
    id <span style="color: #008000">bigint</span>(<span style="color: #666666">20</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> AUTO_INCREMENT,
    gui <span style="color: #008000">varchar</span>(<span style="color: #666666">64</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    first_name <span style="color: #008000">varchar</span>(<span style="color: #666666">32</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    last_name <span style="color: #008000">varchar</span>(<span style="color: #666666">32</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    status <span style="color: #008000">int</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> <span style="color: #666666">0</span>,
    last_update_time <span style="color: #008000; font-weight: bold">timestamp</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> <span style="color: #008000; font-weight: bold">CURRENT_TIMESTAMP</span> <span style="color: #008000; font-weight: bold">ON</span> <span style="color: #008000; font-weight: bold">UPDATE</span> <span style="color: #008000; font-weight: bold">CURRENT_TIMESTAMP</span>,
    create_time <span style="color: #008000; font-weight: bold">timestamp</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    <span style="color: #008000; font-weight: bold">UNIQUE</span> (gui),
    <span style="color: #008000; font-weight: bold">INDEX</span> first_name_ind (first_name),
    <span style="color: #008000; font-weight: bold">INDEX</span> last_name_ind (last_name),
    <span style="color: #008000; font-weight: bold">PRIMARY</span> <span style="color: #008000; font-weight: bold">KEY</span> (id)
) ENGINE<span style="color: #666666">=</span>InnoDB AUTO_INCREMENT<span style="color: #666666">=100000000</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> CHARSET<span style="color: #666666">=</span>utf8;
</pre></div>
			
			<p></p>
			<li><b>Upper case with underscore:</b></li>
			<!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008000; font-weight: bold">CREATE</span> <span style="color: #008000; font-weight: bold">TABLE</span> ACCOUNT(
    ID <span style="color: #008000">bigint</span>(<span style="color: #666666">20</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> AUTO_INCREMENT,
    GUI <span style="color: #008000">varchar</span>(<span style="color: #666666">64</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    FIRST_NAME <span style="color: #008000">varchar</span>(<span style="color: #666666">32</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    LAST_NAME <span style="color: #008000">varchar</span>(<span style="color: #666666">32</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    STATUS <span style="color: #008000">int</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> <span style="color: #666666">0</span>,
    LAST_UPDATE_TIME <span style="color: #008000; font-weight: bold">timestamp</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> <span style="color: #008000; font-weight: bold">CURRENT_TIMESTAMP</span> <span style="color: #008000; font-weight: bold">ON</span> <span style="color: #008000; font-weight: bold">UPDATE</span> <span style="color: #008000; font-weight: bold">CURRENT_TIMESTAMP</span>,
    CREATE_TIME <span style="color: #008000; font-weight: bold">timestamp</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    <span style="color: #008000; font-weight: bold">UNIQUE</span> (GUI),
    <span style="color: #008000; font-weight: bold">INDEX</span> LAST_NAME_IND (FIRST_NAME),
    <span style="color: #008000; font-weight: bold">INDEX</span> LAST_NAME_IND (LAST_NAME),
    <span style="color: #008000; font-weight: bold">PRIMARY</span> <span style="color: #008000; font-weight: bold">KEY</span> (ID)
) ENGINE<span style="color: #666666">=</span>InnoDB AUTO_INCREMENT<span style="color: #666666">=100000000</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> CHARSET<span style="color: #666666">=</span>utf8;
</pre></div>
			
			<p></p>
			<li><b>Capitalize from the second word, just like naming convention in Java:</b></li>
			<!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008000; font-weight: bold">CREATE</span> <span style="color: #008000; font-weight: bold">TABLE</span> Account(
    id <span style="color: #008000">bigint</span>(<span style="color: #666666">20</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> AUTO_INCREMENT,
    gui <span style="color: #008000">varchar</span>(<span style="color: #666666">64</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    firstName <span style="color: #008000">varchar</span>(<span style="color: #666666">32</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    lastName <span style="color: #008000">varchar</span>(<span style="color: #666666">32</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    status <span style="color: #008000">int</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> <span style="color: #666666">0</span>,
    lastUpdateTime <span style="color: #008000; font-weight: bold">timestamp</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> <span style="color: #008000; font-weight: bold">CURRENT_TIMESTAMP</span> <span style="color: #008000; font-weight: bold">ON</span> <span style="color: #008000; font-weight: bold">UPDATE</span> <span style="color: #008000; font-weight: bold">CURRENT_TIMESTAMP</span>,
    createTime <span style="color: #008000; font-weight: bold">timestamp</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    <span style="color: #008000; font-weight: bold">UNIQUE</span> (gui),
    <span style="color: #008000; font-weight: bold">INDEX</span> firstName_ind (firstName),
    <span style="color: #008000; font-weight: bold">INDEX</span> lastName_ind (lastName),
    <span style="color: #008000; font-weight: bold">PRIMARY</span> <span style="color: #008000; font-weight: bold">KEY</span> (id)
) ENGINE<span style="color: #666666">=</span>InnoDB AUTO_INCREMENT<span style="color: #666666">=100000000</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> CHARSET<span style="color: #666666">=</span>utf8;
</pre></div>
			<p></p>
			<p>All of them are good naming policies and supported in abacus-common. 
			However, we recommend "lower case with underscore" more than other two policies(Maybe, just because of personal experiences).</p>

			<p></p>
			<p>Here is also a bad example:</p>
			<!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008000; font-weight: bold">CREATE</span> <span style="color: #008000; font-weight: bold">TABLE</span> account(
    id <span style="color: #008000">bigint</span>(<span style="color: #666666">20</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> AUTO_INCREMENT,
    gui <span style="color: #008000">varchar</span>(<span style="color: #666666">64</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    first_name <span style="color: #008000">varchar</span>(<span style="color: #666666">32</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    status <span style="color: #008000">int</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> <span style="color: #666666">0</span>,
    last_name <span style="color: #008000">varchar</span>(<span style="color: #666666">32</span>) <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    lastupdatetime <span style="color: #008000; font-weight: bold">timestamp</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> <span style="color: #008000; font-weight: bold">CURRENT_TIMESTAMP</span> <span style="color: #008000; font-weight: bold">ON</span> <span style="color: #008000; font-weight: bold">UPDATE</span> <span style="color: #008000; font-weight: bold">CURRENT_TIMESTAMP</span>,
    CREATE_TIME <span style="color: #008000; font-weight: bold">timestamp</span> <span style="color: #008000; font-weight: bold">NOT</span> <span style="color: #008000; font-weight: bold">NULL</span>,
    <span style="color: #008000; font-weight: bold">UNIQUE</span> (gui),
    <span style="color: #008000; font-weight: bold">INDEX</span> first_name_ind (first_name),
    <span style="color: #008000; font-weight: bold">INDEX</span> last_name_ind (last_name),
    <span style="color: #008000; font-weight: bold">PRIMARY</span> <span style="color: #008000; font-weight: bold">KEY</span> (id)
) ENGINE<span style="color: #666666">=</span>InnoDB AUTO_INCREMENT<span style="color: #666666">=100000000</span> <span style="color: #008000; font-weight: bold">DEFAULT</span> CHARSET<span style="color: #666666">=</span>utf8;
</pre></div>
			<p></p>
			<p>1, Different naming policies for "first_name", "lastupdatetime", "CREATE_TIME". 2, it's hard for program to judge "lastupdatetime" is one word or a composite of several words. 3, columns are not ordered properly: "first_name", "status", "last_name"</p>
			<p>Although it's not mandatory, we strongly recommend that all the tables/columns should be named with a consistent naming policy and organized with proper order.
			   Any thing messed up here, it will also mess up the auto-generated classes, and you codes, and json/xml you may need, and... your heads and other people's... 
			   We think it's important and worth to spend couple of hours or even days on defining a good table or domain model. Every minute spend on it will be ten times rewarded later.</p>
		</div>

	</div>
</body>

</html>